import { requestClient } from '#/api/request';

export namespace workshopAPI {
  export interface Workshop {
    code: number;
    msg: string;
    rows: [];
    total: number;
  }
}

export namespace WorkshopApi {
  export type Params = object;

  export interface Datum {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: Params;
    workshopId: number;
    workshopCode: string;
    workshopName: string;
    area: null | number;
    charge: null | string;
    chargeId: null;
    enableFlag: string;
    attr1: null;
    attr2: null;
    attr3: number;
    attr4: number;
  }

  export interface GetWorkshopListResp {
    msg: string;
    code: number;
    data: Datum[];
  }
}

export const getWorkshopList = (params?: {
  itemTypeId?: number;
  page?: number;
  pageSize?: number;
}) => {
  return requestClient.get<workshopAPI.Workshop>('/mes/md/workshop/list', {
    params,
  });
};

/**
 * @description: 获取所有的车间
 */
export const workshopAll = () =>
  requestClient.get<WorkshopApi.GetWorkshopListResp>(
    '/mes/md/workshop/listAll',
  );

// 删除车间
export const deleteWorkshop = (id: string) =>
  requestClient.delete<WorkshopApi.GetWorkshopListResp>(
    `/mes/md/workshop/${id}`,
  );

// 新增车间
export const addWorkshop = (data: WorkshopApi.Datum) =>
  requestClient.post<WorkshopApi.GetWorkshopListResp>('/mes/md/workshop', data);

// 修改车间
export const updateWorkshop = (data: WorkshopApi.Datum) =>
  requestClient.put<WorkshopApi.GetWorkshopListResp>('/mes/md/workshop', data);
